package com.moyq5.mvc.maker.test.bean.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.moyq5.mvc.maker.test.bean.enums.IncomeType;

/**
 * 收益流水，记录线下投币收入和线上支付收入
 * @author Moyq5
 * @date 2018年4月13日
 */
@Entity
@Table(name = "iot_income")
@DynamicUpdate
public class IotIncome implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 收益ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "income_id")
	private Long incomeId;
	/**
	 * 商家
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merch_id")
	private Merch merch;
	/**
	 * 门店
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "shop_id")
	private Shop shop;
	/**
	 * 设备
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "device_id")
	private IotDevice device;
	/**
	 * 收益类型
	 */
    @Enumerated(EnumType.ORDINAL)
    @Column(name = "type", columnDefinition="int(1) default '0'")
	private IncomeType type;
    /**
	 * 金额
	 */
	@Column(name = "amount", precision = 10, scale = 2, nullable = false)
	private BigDecimal amount;
	/**
	 * 交易订单ID，根据收益类型获知具体哪类订单
	 */
	@Column(name = "ref_id", precision = 15, scale = 0)
	private Long refId;
    /**
	 * 收益时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	public IotIncome() {
		
	}
	
	public IotIncome(Shop shop, BigDecimal amount) {
		this.shop = shop;
		this.amount = amount;
	}
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
	}
	
	public Long getIncomeId() {
		return incomeId;
	}
	public void setIncomeId(Long incomeId) {
		this.incomeId = incomeId;
	}
	public Merch getMerch() {
		return merch;
	}
	public void setMerch(Merch merch) {
		this.merch = merch;
	}
	public Shop getShop() {
		return shop;
	}
	public void setShop(Shop shop) {
		this.shop = shop;
	}
	public IotDevice getDevice() {
		return device;
	}
	public void setDevice(IotDevice device) {
		this.device = device;
	}
	public IncomeType getType() {
		return type;
	}
	public void setType(IncomeType type) {
		this.type = type;
	}
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	public Long getRefId() {
		return refId;
	}
	public void setRefId(Long refId) {
		this.refId = refId;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	
}
